FileTreePanel = Ext.extend(Ext.tree.TreePanel, {
	treeMenu    : null, // 树右键菜单
	actions		: null,
	constructor : function(_cfg) {
		Ext.apply(this, _cfg);
		this.actions = [
			new Ext.Action({
				text : '新建文件夹',
				iconCls : 'db-icn-folder-new',
				handler : function() 
				{
					this.createFolder();
				},
				selectNode : null,
				scope : this
			}),
			new Ext.Action({
				text : '删除文件夹',
				iconCls : 'db-icn-delete',
				handler : function() {
					this.deleteFolder();
				},
				scope : this
			})
        ];
		this.treeMenu = new Ext.menu.Menu({
				items:
				[
				      this.actions[0]//,this.actions[1]
		        ]
		});
		FileTreePanel.superclass.constructor.call(this, {
			region : 'center',
			split : true,
			margins : '-1 -1 2 -1',
			autoScroll : true,
			lines : true,
			loader : new Ext.tree.TreeLoader({
				dataUrl : getRootPath()+'/fileOperate.html?method=getDirectories',
				listeners:{
					beforeload:function(treeLoader, node) 
					{
				      	//this.baseParams.node = node.id;
				    }
				}
			}),
			root : new Ext.tree.AsyncTreeNode({
				id : '*',
				iconCls : 'db-icn-world',
				text : '根目录'
			})
		});
	},
	listeners : 
	{
		"contextmenu" : function(_node,e)
		{
			e.preventDefault();
			this.actions[0].selectNode = _node;
			if(_node.id == "*")
			{
				this.actions[1].hidden = true;
			}
			this.treeMenu.showAt(e.getXY());
		}
	},
	createFolder : function()
	{
		var _node = this.actions[0].selectNode;
		var path = '/' + (Ext.isEmpty(_node.id) ? '' : _node.id);
		path = (path == "/*" ? "/" : path);//特殊节点处理
		Ext.Msg.prompt('新建文件夹','请输入文件夹名称',function(btn, text)
		{
		    if (btn == 'ok')
		    {
				Ext.Ajax.request({
					url : getRootPath()+'/fileOperate.html?method=createFolder',
					callback : function(options, success, response) 
					{
						var result = Ext.util.JSON.decode(response.responseText);
						if (result.success) 
						{
							//判断要展开节点数据是否已加载。如果数据没加载,直接展开;否则，先load再展开
						   	if(_node.childrenRendered)
						   	{
								this.getLoader().load(_node);	
						   	}
						   	_node.expand(false, false);
						} 
						else 
						{
							Ext.Msg.show(
							{
							   title:'错误提示',
							   msg: '新建文件夹操作失败. 请重试!',
							   buttons: Ext.Msg.OK,
							   icon: Ext.Msg.ERROR
							});
						}
					},
					params : 
					{
						path : path,
						name : text
					},
					scope : this
				});
		    }
		},this);
	},
	deleteFolder : function()
	{
		
	}
	
});

